package main

import "fmt"

func add(params ...int) (sum int) {
	for _, v := range params {
		sum += v
	}
	return
}

type sub func(a, b int) int

func subImpl(a, b int) int {
	return a - b
}

func filter(score []int, f func(int) bool) []int {
	reSlice := make([]int, 0)
	for _, v := range score {
		if f(v) {
			reSlice = append(reSlice, v)
		}
	}
	return reSlice
}

//func filter(score *[]int) {
//	reSlie := make([]int, 0)
//	for _, v := range *score {
//		if v >= 60 {
//			reSlie = append(reSlie, v)
//		}
//	}
//	*score = reSlie
//}

func main() {
	//... 值传递   slice是引用传递
	slice := []int{1, 2, 3, 4, 5}
	fmt.Println(add(slice...))
	fmt.Println(add(1, 2, 3))
	//	...函数参数不定长
	arr := [...]int{1, 2, 3}
	fmt.Printf("%T\n", arr)

	//myFunc := add
	//fmt.Printf("%T", myFunc)
	//匿名函数
	result := func(a, b int) int {
		return a + b
	}(1, 2)
	fmt.Println(result)
	//var mySub sub = subImpl
	var mySub2 sub = func(a, b int) int { return a - b }
	fmt.Println(mySub2(1, 2))

	score := []int{10, 50, 80, 90, 85}
	//filter(&score)
	//fmt.Println(score)
	fmt.Println(filter(score, func(a int) bool {
		if a >= 90 {
			return true
		} else {
			return false
		}
	}))

}
